var app = getApp();

Page({
  data: {
   pinji_detail:{},
   contents: '',
  },
  pinji_detail: function (detail_id) { //拼机详情
    var that = this;
    if (detail_id){
      wx.request({
        url: app.api.kzdsurl + app.interface.buy_feiji_xq,
        method: 'post',
        data: {id: detail_id},
        header: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res.data.data);
          that.setData({
            contents: res.data.data.intro,
          });
          //endInitData
        },
        fail: function (e) {
          wx.showToast({
            title: '网络异常！',
            duration: 2000
          });
        },
      });
    }
  
  },
  lookmoredetail: function (e) {
    var that = this;
    var feiji_id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../feijidetail/index?feiji_id='+feiji_id
    })
  },
  
  onLoad: function (options) {
    // var that = this;
    this.pinji_detail(options.detail_id)
 
  },
  requestPayment: (order_id, openid)=>{
          var self = this;
          // self.setData({
          //   loading: true
          // })
          // 此处需要先调用wx.login方法获取code，然后在服务端调用微信接口使用code换取下单用户的openId
          // 具体文档参考https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-login.html?t=20161230#wxloginobject


          // console.log(self.data.order_id)
          // console.log(self.data.openid)
          // console.log(self.data.paperId)
          
          wx.request({
            // url: "https://caca.qianlh.com/home/jiekou/Wx_Pay",
            url: app.api.kzdsurl+app.interface.buy_feiji_xq,
            data: {
              'order_id': order_id,//订单号
              'openid': openid
            },
            header: {//请求头
              "Content-Type": "application/x-www-form-urlencoded"
            },
            method: "POST",//get为默认方法/POST
            success: (res)=> {
              console.log('是统一下单方法返回值了');
              console.log(res.data);
              wx.requestPayment({
                'nonceStr': res.data.nonceStr,
                'package': res.data.package,
                'signType': res.data.signType,
                'timeStamp': res.data.timeStamp,
                'paySign': res.data.paySign,
                'success': (res2) => {
                  console.log(res2);

                  wx.showToast({
                    title: '支付成功',
                    icon: 'succes',
                    duration: 500,
                    mask: true
                  })
                  setTimeout(() => {
                    wx.redirectTo({
                      url: '../payover/payover',
                    })
                  }, 600)
                },
                'fail': (res3) => {
                  console.log(res3);
                }
              })
            }
          })
        },
  joinAircraft: function () {
    var that = this;
    wx.getStorage({
      key: 'openid',
      success: (res)=>{
        // success
        var openid = res.data;
        // that.requestPayment(openid)
      }
    })
  },
  onShareAppMessage: function () {
    return {
      title: '宠物美容学校',
      path: '/pages/index/index',
      success: function(res) {
        // 分享成功
      },
      fail: function(res) {
        // 分享失败
      }
    }
  }



});